package com.g.jnitext;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Vector;

public class MainActivity extends AppCompatActivity {
    private PrintConnect PrintConnect;
    private boolean isNew7S = false;
    private int con = 0, speed = 7, width = 2, height = 60, count = 0, alignment = 0, underline = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      JNITest test=new JNITest();
      TextView tv= findViewById(R.id.tv);
     tv.setText(test.getString());
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pt1d();
            }
        });
       // isNew7S = Build.MODEL.equals("msm8909_512") && Build.VERSION.RELEASE.equals("5.1.1") && Build.MANUFACTURER.equals("unknown");
        //   ScanConnect = new ScanConnect(this,isNew7S,mHandler,MSG_WHAT);//ScanConnect.scanConnect;
    PrintConnect = new PrintConnect(this, true);
   }
//    //打印标签
    public void pt1d() {
        LabelCommand tsc = new LabelCommand();
        tsc.addSize(50, 30); // 设置标签尺寸，按照实际尺寸设置 (50*8,30*8) (400,240)
        tsc.addReference(0, 0);//设置原点坐标
        tsc.addCls();//清除打印缓冲区
//绘制文本
        tsc.addText(20, 20, LabelCommand.FONTTYPE.FONT_2, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,
                "好好学习，天天向上");
//绘制一维码
        tsc.add1DBarcode(20, 50, LabelCommand.BARCODETYPE.CODE128, 50, LabelCommand.READABEL.EANBEL, LabelCommand.ROTATION.ROTATION_0, "123456");
//绘制图片
        tsc.addBitmap(20, 110, LabelCommand.BITMAP_MODE.OVERWRITE, 120, BitmapFactory.decodeResource(getResources(), R.mipmap.print_icon1));
        tsc.addPrint(1, 1); // 打印标签
        Vector<Byte> datas = tsc.getCommand(); // 发送数据
        byte[] bytes = GpUtils.ByteTo_byte(datas);
        try {
            PrintConnect.send(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    @Override
    protected void onPause() {
        super.onPause();
        PrintConnect.stop();


    }

    @Override
    protected void onResume() {
        super.onResume();
        PrintConnect = new PrintConnect(this, true);

    }

}
